<?php

/**
 * @see Zend_Application_Bootstrap_Bootstrap
 */
require_once 'Zend/Application/Bootstrap/Bootstrap.php';

/**
 * Classe para inicializacao da aplicacao
 *
 * @category Tavs
 * @package Tavs_Application_Bootstrap
 *
 * @author Tales Santos <tales.augusto.santos>
 *
 */
class Tavs_Application_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	/**
	 * Configura os autoloaders.
	 *
	 * @return void
	 */
	protected function _initLoader()
	{
		$autoloader = Zend_Loader_Autoloader::getInstance();
		$autoloader->setFallbackAutoloader(true);

		return $autoloader;
	}

	/**
	 * Inicializa e retorna o frontController
	 *
	 * @return Zend_Controller_Front
	 */
	protected function _getFrontController()
	{
		return $this->bootstrap('frontController')->getResource('frontController');
	}

	/**
	 * Inicializa e retorna o request
	 *
	 * @return Zend_Controller_Front
	 */
	protected function _getRequest()
	{
		return $this->bootstrap('request')->getResource('request');
	}

	/**
	 * Inicializa o objeto de requisicao
	 *
	 * @return Zend_Controller_Request_Http
	 */
	protected function _initRequest()
	{
		$request = new Zend_Controller_Request_Http();
		$this->_getFrontController()->setRequest($request);

		return $request;
	}

	/**
	 * Configura o objeto de renderização
	 *
	 * @return Zend_View_Interface
	 */
	protected function _initView()
	{
		$view = new Zend_View();
		$view
			->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper')
			->addHelperPath('Tavs/View/Helper', 'Tavs_View_Helper')
			->setEncoding('UTF-8');

		$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
		$viewRenderer->setView($view);
		Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

		//configura o layout
		Zend_Layout::startMvc(array(
			'view' => $view
		));

		return $view;
	}

	/**
	 * Inicializa os plugins
	 *
	 * @return Zend_Controller_Front
	 */
	protected function _initControllerPlugins()
	{
		$this->bootstrap('view');

		$front = $this->_getFrontController();

		$options = array();

		if (property_exists($this, '_pluginViewOptions')) {
			$options = (array)$this->_pluginViewOptions;
		}

		$front
			->registerPlugin(new Tavs_Controller_Plugin_View($options), 98)
			->registerPlugin(new Tavs_Controller_Plugin_Layout(), 103);

		return $front;
	}

	/**
	 * Inicializa o objeto de localizacao
	 *
	 * @return Zend_Locale
	 */
	protected function _initLocale()
	{
		$locale = new Zend_Locale('auto');
		return $locale;
	}
}